﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AuthorityRoleMenuRelaEdit.aspx.cs" Inherits="OpSystem.Manage.authority.AuthorityRoleMenuRelaEdit" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <!-- #include file="~/include/header.html" -->
    <style type="text/css">
        .panel-mainhead {
            border-bottom: 1px solid #d2d6de;
            line-height: 30px;
            font-weight: bold;
        }
        .panel-mainhead input {
                margin-top: 9px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="row-fluid">
            <div class="panel-group" id="accordion">
                <%=strHtml %>
            </div>
            <div class="control-group" style="margin-top: 10px; text-align: center;">

                <div class="controls">
                    <button class="btn btn-primary" type="button" id="sure">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                </div>
            </div>
        </div>
    </form>
    <!-- #include file="~/include/footer.html" -->
    <script type="text/javascript">
        $("#cancel").click(function () {
            BMCW.closeTopLayer();
        });
        $("#sure").click(function () {
            Save();
        });
        $("#accordion").find(".panel").each(function(){
            $(this).on('hide.bs.collapse show.bs.collapse', '.panel-collapse', function (e) {
                var $this = $(this)
                $this.prev().find("span").toggleClass("glyphicon-plus");
                $this.prev().find("span").toggleClass("glyphicon-minus");
            });
            var $this = $(this);
            $(this).find(".panel-title input:checkbox").click(function(){
                var $thisCheck = false;
                if ($(this).prop("checked") == true) {
                    $(this).prop("checked", true);
                    $thisCheck = true;
                } else {
                    $(this).prop("checked", false);
                }
                $this.find(".panel-body input:checkbox").each(function(){
                    if ($thisCheck) {
                        $(this).prop("checked", true);
                    } else {
                        $(this).prop("checked", false);
                    }
                })
            });
            $(this).find(".panel-mainhead input:checkbox").click(function(){
                var pid = $(this).val();
                var $thisCheck = false;
                if ($(this).prop("checked") == true) {
                    $(this).prop("checked", true);
                    $thisCheck = true;
                } else {
                    $(this).prop("checked", false);
                }
                $this.find(".panel-body ul").each(function(){
                    if($(this).attr("data-parent")==pid)
                    {
                        $(this).find("li input:checkbox").each(function(){
                            if ($thisCheck) {
                                $(this).prop("checked", true);
                            } else {
                                $(this).prop("checked", false);
                            }
                        })
                    }
                });
                if($this.find(".panel-body").find("[type=checkbox]:checked").length==0)
                {
                    $this.find(".panel-title input:checkbox").prop("checked", false);
                }else
                {
                    $this.find(".panel-title input:checkbox").prop("checked", true);
                }
            });
            $(this).find(".panel-body ul li input:checkbox").click(function(){
                var pid = $(this).parent().parent().attr("data-parent");
                var $thisCheck = false;
                if ($(this).prop("checked") == true) {
                    $(this).prop("checked", true);
                    $thisCheck = true;
                } else {
                    $(this).prop("checked", false);
                }
                $this.find(".panel-mainhead input:checkbox").each(function(){
                    if($(this).val()==pid)
                    {
                        if($(this).parent().next("ul").find("[type=checkbox]:checked").length==0)
                        {
                            $(this).prop("checked", false);
                        }else{
                            $(this).prop("checked", true);
                        }
                    }
                });
                if($this.find(".panel-body").find("[type=checkbox]:checked").length==0)
                {
                    $this.find(".panel-title input:checkbox").prop("checked", false);
                }else
                {
                    $this.find(".panel-title input:checkbox").prop("checked", true);
                }
            });
        })
        function Save() {
            var $checkedlist = "";
            var $selectList = $("#accordion");
          
            // BMCW.loading();
            $selectList.find(".ckb").each(function () {
                var $this = $(this);
                if ($this.prop("checked") == true) {
                    if ($checkedlist == "") {
                        $checkedlist += $this.val();
                    } else {
                        $checkedlist += "," + $this.val();
                    }
                }

            });
            var url = '<%=GetPageUrl("authorityrolelist.aspx")%>';
            var $data = "action=saverolemenurela&roleid=<%=intRoleID%>&menuid=" + $checkedlist;
            $.ajax({
                type: "POST",
                url: "../ajax/api.aspx",
                timeout: 20000,
                data: $data,
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    //数据处理中

                },
                success: function (data, textStatus) {
                    //请求成功
                    if (!data.IsError) {
                        BMCW.msg("权限设置成功", url);
                    } else {
                        BMCW.alert(data.Message);
                    }


                },
                complete: function (XMLHttpRequest, textStatus) {
                    // BMCW.closeAll();
                },
                error: function () {
                    //请求出错处理
                }
            });
        }
     
        <%=strMessage %>
    </script>
</body>
</html>
